package com.ctrip.demo.objectmapper;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.Serializable;
import java.util.List;

public class  ObjectMapperTest{

    public static void main(String[] args) {
        String data = "[{\"filename\":\"xxxxx.txt\",\"url\":\"http://ws.downloadfile.fx.uat.qa.nt.ctripcorp.com/files/xxxxx.txt\",\"type\":\"txt\"},{\"filename\":\"xxxxx.pdf\",\"url\":\"http://ws.downloadfile.fx.uat.qa.nt.ctripcorp.com/files/xxxxx.pdf\",\"type\":\"pdf\"}]";


        try {
            ObjectMapper objectMapper = new ObjectMapper();
            List<Attachment> attachment = objectMapper.readValue(data, new TypeReference<List<Attachment>>() {
            });
            attachment.stream().forEach(System.out::println);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
}
